﻿#ifndef __MultiActivityList_H__
#define __MultiActivityList_H__

#include "pch.h"
#include "cvsreader.h"
#include "config.h"
#include "noncopyable.h"

// generate by ProtoGen at date: 2017/9/11 10:10:53


class MultiActivityList : public CVSReader, public noncopyable
{
public:

	struct RowData
	{
		int	ID;
		string	Name;
		string	OpenWeek;
		vector<Sequence<uint, 2>>	OpenDayTime;
		uint	GuildLevel;
		int	DayCountMax;
		int	SystemID;
		string	RewardTips;
		string	OpenDayTips;
		string	Icon;
		bool	NeedOpenAgain;
		bool	FairMode;
		uint	OpenServerWeek;
		uint	PushIcon;
		vector<Sequence<uint, 2>>	DropItems;
		bool	HadShop;
		bool	WxGuildTask;
		string	AtlasPath;

		void CopyFrom(RowData *pRowData)
		{
			this->ID=pRowData->ID;
			this->Name=pRowData->Name;
			this->OpenWeek=pRowData->OpenWeek;
			this->OpenDayTime=pRowData->OpenDayTime;
			this->GuildLevel=pRowData->GuildLevel;
			this->DayCountMax=pRowData->DayCountMax;
			this->SystemID=pRowData->SystemID;
			this->RewardTips=pRowData->RewardTips;
			this->OpenDayTips=pRowData->OpenDayTips;
			this->Icon=pRowData->Icon;
			this->NeedOpenAgain=pRowData->NeedOpenAgain;
			this->FairMode=pRowData->FairMode;
			this->OpenServerWeek=pRowData->OpenServerWeek;
			this->PushIcon=pRowData->PushIcon;
			this->DropItems=pRowData->DropItems;
			this->HadShop=pRowData->HadShop;
			this->WxGuildTask=pRowData->WxGuildTask;
			this->AtlasPath=pRowData->AtlasPath;

		}
	};

	std::unordered_map<int,int> ID_Index;


    RowData *GetByID(const int &key)
    {
        auto i = ID_Index.find(key);
        return (i == ID_Index.end()) ? NULL : Table[i->second];
    }
    

	virtual bool OnHeaderLine(char **Fields, int FieldCount)
	{
		const char *Headers[] = { "ID", "Name", "OpenWeek", "OpenDayTime", "GuildLevel", "DayCountMax", "SystemID", "RewardTips", "OpenDayTips", "Icon", "NeedOpenAgain", "FairMode", "OpenServerWeek", "PushIcon", "DropItems", "HadShop", "WxGuildTask", "AtlasPath",  };
		const int HeadersCount = sizeof(Headers)/sizeof(Headers[0]);
		//assert(FieldCount == HeadersCount);
		return MapColHeader(Headers, HeadersCount, Fields, FieldCount);
	}

	virtual bool OnCommentLine(char **Fields, int FieldCount)
	{
		return true;
	}

	void CopyFrom(MultiActivityList  *pSrcTable)
	{
		for (UINT32 i = 0; i< pSrcTable->Table.size(); i++)
		{
			RowData* pSrcRow = pSrcTable->Table[i];
            RowData *pDstRow = GetByID(pSrcRow->ID);
            if(pDstRow != NULL)
            {
                pDstRow->CopyFrom(pSrcRow);
            }
            else
            {
                RowData* pNewRow = new RowData();
                pNewRow->CopyFrom(pSrcRow);
                Table.push_back(pNewRow);
                ID_Index[pNewRow->ID]=Table.size()-1;
            }

		}
	}

	virtual bool OnLine(char **Fields, int FieldCount)
	{
		RowData *pRow = new RowData();
		RowData &row = *pRow;
		m_ColNum = 0;

		if (!Parse(Fields[m_ColMap[0]], row.ID)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[1]], row.Name)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[2]], row.OpenWeek)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[3]], row.OpenDayTime)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[4]], row.GuildLevel)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[5]], row.DayCountMax)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[6]], row.SystemID)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[7]], row.RewardTips)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[8]], row.OpenDayTips)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[9]], row.Icon)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[10]], row.NeedOpenAgain)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[11]], row.FairMode)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[12]], row.OpenServerWeek)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[13]], row.PushIcon)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[14]], row.DropItems)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[15]], row.HadShop)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[16]], row.WxGuildTask)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[17]], row.AtlasPath)) return false; ++m_ColNum;

		
		Table.push_back(pRow);

		ID_Index[row.ID] = Table.size()-1;


		return true;
	}

	~MultiActivityList ()
	{
		Clear();
	}

	void Clear()
	{
		for (UINT32 i = 0; i < Table.size(); ++i)
		{
			delete Table[i];
		}

		Table.clear();

		ID_Index.clear();

	}

	std::vector<RowData*> Table;
};

#endif